package com.icehand.axon.demo.controller;

import com.icehand.axon.demo.command.commands.CreateAccountCommand;
import com.icehand.axon.demo.command.commands.WithdrawMoneyCommand;
import com.icehand.axon.demo.common.domain.AccountId;
import lombok.extern.slf4j.Slf4j;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author icehand
 */
@RestController
@RequestMapping("/bank")
@Slf4j
public class BankAccountController {
    @Autowired
    private CommandGateway commandGateway;

    /**
     * 创建用户
     */
    @RequestMapping(method = RequestMethod.POST)
    public void create(CreateAccountCommand command) {
        AccountId id = new AccountId();
        command.setAccountId(id);
        log.info("create account id {}",id.toString());
        commandGateway.send(command);

    }

    /**
     * 提现
     */
    @RequestMapping(method = RequestMethod.PUT)
    public void draw(WithdrawMoneyCommand command) {
        commandGateway.send(command);

    }
}
